package com.xiaolun;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author 硕鼠
 * @Date 2020/6/13 18:42
 * @Version 1.0
 * @Description 文件说明
 */
public class LogoutServlet extends HttpServlet {
    @Override //注销功能
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Object user_session = req.getSession().getAttribute("USER_SESSION");

        if (user_session != null){
            //如果session不为null，说明有用户登录，我们移除session。
            req.getSession().removeAttribute("USER_SESSION");
            resp.sendRedirect("/s1/login.jsp"); //重新回到登录界面
        }else {
            resp.sendRedirect("/s1/login.jsp"); //重新回到登录界面
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
